home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1995 June / MacFormat 25.iso / Shareware City / Developers / OutOfPhase1.1 Source / OutOfPhase Folder / TieTrackPixel.c < prev    next >
Text File  |  1994-08-15  |  7KB  |  219 lines

  1. /* TieTrackPixel.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "TieTrackPixel.h"
  31. #include "Array.h"
  32. #include "Memory.h"
  33.  
  34.  
  35. typedef struct
  36.     {
  37.         long                        SourceHorizontalPixel;
  38.         long                        SourceVerticalPixel;
  39.         long                        DestinationHorizontalPixel;
  40.         long                        DestinationVerticalPixel;
  41.     } TiePixelRec;
  42.  
  43.  
  44. struct TieTrackPixelRec
  45.     {
  46.         ArrayRec*                ListOfTieThangs; /* of TiePixelRec's */
  47.     };
  48.  
  49.  
  50. /* create a new tie pixel tracking object */
  51. TieTrackPixelRec*        NewTieTrackPixel(void)
  52.     {
  53.         TieTrackPixelRec*    TieTrackPixel;
  54.  
  55.         TieTrackPixel = (TieTrackPixelRec*)AllocPtrCanFail(sizeof(TieTrackPixelRec),
  56.             "TieTrackPixelRec");
  57.         if (TieTrackPixel == NIL)
  58.             {
  59.              FailurePoint1:
  60.                 return NIL;
  61.             }
  62.         TieTrackPixel->ListOfTieThangs = NewArray();
  63.         if (TieTrackPixel->ListOfTieThangs == NIL)
  64.             {
  65.              FailurePoint2:
  66.                 ReleasePtr((char*)TieTrackPixel);
  67.                 goto FailurePoint1;
  68.             }
  69.         return TieTrackPixel;
  70.     }
  71.  
  72.  
  73. /* delete a tie pixel tracking object */
  74. void                                DisposeTieTrackPixel(TieTrackPixelRec* TieTrackPixel)
  75.     {
  76.         long                            Limit;
  77.         long                            Scan;
  78.  
  79.         CheckPtrExistence(TieTrackPixel);
  80.         Limit = ArrayGetLength(TieTrackPixel->ListOfTieThangs);
  81.         for (Scan = 0; Scan < Limit; Scan += 1)
  82.             {
  83.                 TiePixelRec*            PixelRec;
  84.  
  85.                 PixelRec = (TiePixelRec*)ArrayGetElement(TieTrackPixel->ListOfTieThangs,Scan);
  86.                 ReleasePtr((char*)PixelRec);
  87.             }
  88.         DisposeArray(TieTrackPixel->ListOfTieThangs);
  89.         ReleasePtr((char*)TieTrackPixel);
  90.     }
  91.  
  92.  
  93. /* add a new point pair to the tracking thang */
  94. MyBoolean                        AddTieTrackPixelElement(TieTrackPixelRec* TieTrackPixel,
  95.                                             long StartX, long StartY, long EndX, long EndY)
  96.     {
  97.         TiePixelRec*            PixelRec;
  98.  
  99.         CheckPtrExistence(TieTrackPixel);
  100.         PixelRec = (TiePixelRec*)AllocPtrCanFail(sizeof(TiePixelRec),"TiePixelRec");
  101.         if (PixelRec == NIL)
  102.             {
  103.              FailurePoint1:
  104.                 return False;
  105.             }
  106.         PixelRec->SourceHorizontalPixel = StartX;
  107.         PixelRec->SourceVerticalPixel = StartY;
  108.         PixelRec->DestinationHorizontalPixel = EndX;
  109.         PixelRec->DestinationVerticalPixel = EndY;
  110.         if (!ArrayAppendElement(TieTrackPixel->ListOfTieThangs,PixelRec))
  111.             {
  112.              FailurePoint2:
  113.                 ReleasePtr((char*)PixelRec);
  114.                 goto FailurePoint1;
  115.             }
  116.         return True;
  117.     }
  118.  
  119.  
  120. struct TieIntersectListRec
  121.     {
  122.         ArrayRec*                ListOfOnes;
  123.     };
  124.  
  125.  
  126. /* obtain an array of all ties which are in some manner intersecting the */
  127. /* specified X interval */
  128. TieIntersectListRec*    GetTieTrackPixelIntersecting(TieTrackPixelRec* TieTrackPixel,
  129.                                             long XLocStart, long XLocWidth)
  130.     {
  131.         long                            ItemCount;
  132.         long                            Scan;
  133.         long                            Limit;
  134.         TieIntersectListRec*    List;
  135.  
  136.         CheckPtrExistence(TieTrackPixel);
  137.         List = (TieIntersectListRec*)AllocPtrCanFail(sizeof(TieIntersectListRec),
  138.             "TieIntersectListRec");
  139.         if (List == NIL)
  140.             {
  141.              FailurePoint1:
  142.                 return NIL;
  143.             }
  144.         Limit = ArrayGetLength(TieTrackPixel->ListOfTieThangs);
  145.  
  146.         /* find out how many elements need to be allocated */
  147.         ItemCount = 0;
  148.         for (Scan = 0; Scan < Limit; Scan += 1)
  149.             {
  150.                 TiePixelRec*            PixelRec;
  151.  
  152.                 PixelRec = (TiePixelRec*)ArrayGetElement(TieTrackPixel->ListOfTieThangs,Scan);
  153.                 if ((PixelRec->SourceHorizontalPixel < XLocStart + XLocWidth)
  154.                     && (PixelRec->DestinationHorizontalPixel > XLocStart))
  155.                     {
  156.                         /* some part of the tie-line is visible on the screen */
  157.                         ItemCount += 1;
  158.                     }
  159.             }
  160.  
  161.         /* allocate the array */
  162.         List->ListOfOnes = NewArrayReserveSpace(ItemCount);
  163.         if (List->ListOfOnes == NIL)
  164.             {
  165.              FailurePoint2:
  166.                 ReleasePtr((char*)List);
  167.                 goto FailurePoint1;
  168.             }
  169.  
  170.         /* generate the intersection list */
  171.         ItemCount = 0;
  172.         for (Scan = 0; Scan < Limit; Scan += 1)
  173.             {
  174.                 TiePixelRec*            PixelRec;
  175.  
  176.                 PixelRec = (TiePixelRec*)ArrayGetElement(TieTrackPixel->ListOfTieThangs,Scan);
  177.                 if ((PixelRec->SourceHorizontalPixel < XLocStart + XLocWidth)
  178.                     && (PixelRec->DestinationHorizontalPixel > XLocStart))
  179.                     {
  180.                         ArrayAppendElement(List->ListOfOnes,PixelRec);
  181.                     }
  182.             }
  183.  
  184.         return List;
  185.     }
  186.  
  187.  
  188. /* dispose of the tie intersection list */
  189. void                                DisposeTieTrackIntersectList(TieIntersectListRec* List)
  190.     {
  191.         CheckPtrExistence(List);
  192.         /* DON'T delete the elements of the list */
  193.         DisposeArray(List->ListOfOnes);
  194.         ReleasePtr((char*)List);
  195.     }
  196.  
  197.  
  198. /* find out how many elements there are in the intersection list */
  199. long                                GetTieTrackIntersectListLength(TieIntersectListRec* List)
  200.     {
  201.         CheckPtrExistence(List);
  202.         return ArrayGetLength(List->ListOfOnes);
  203.     }
  204.  
  205.  
  206. /* get the drawing information about a particular tie thang */
  207. void                                GetTieTrackIntersectElement(TieIntersectListRec* List, long Index,
  208.                                             long* StartX, long* StartY, long* EndX, long* EndY)
  209.     {
  210.         TiePixelRec*            PixelRec;
  211.  
  212.         CheckPtrExistence(List);
  213.         PixelRec = (TiePixelRec*)ArrayGetElement(List->ListOfOnes,Index);
  214.         *StartX = PixelRec->SourceHorizontalPixel;
  215.         *StartY = PixelRec->SourceVerticalPixel;
  216.         *EndX = PixelRec->DestinationHorizontalPixel;
  217.         *EndY = PixelRec->DestinationVerticalPixel;
  218.     }
  219.